package org.blankie.util;

import java.util.AbstractCollection;
import java.util.Iterator;
import org.blankie.lang.Validate;

/**
 *
 * @author francois.mora@blankie.org
 */
public class CollectionCollector<E> extends AbstractCollection<E> implements Collector<E> {

    private final Collector<E> collector;

    private int size;
    
    public CollectionCollector(Collector<E> collector) {
        Validate.parameterNotNull("collector", collector);
        this.collector = collector;
        this.size = 0;
    }

    @Override
    public boolean add(E e) {
        collector.collect(e);
        size++;
        return true;
    }

    @Override
    public void close() {
        collector.close();
    }

    @Override
    public void collect(E element) {
        add(element);
    }

    @Override
    public void failed(Exception e) {
        collector.failed(e);
    }

    @Override
    public Iterator iterator() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setSize(int size) {
        collector.setSize(size);
    }

    @Override
    public int size() {
        return size;
    }

}
